<?php

require_once 'common/common.php';
require_once 'common/conn.php';

$resultArray = array();
if (isset($_GET['usercode']) && isset($_GET['start']) && isset($_GET['limit'])) {
    $usercode = trim($_GET['usercode']);
    $start = trim($_GET['start']);
    $limit = trim($_GET['limit']);
    $db = new DBC();
    $sql = "SELECT DISTINCT m.flashcode AS code,m.name,m.url,m.version,m.price,m.goodprice,m.promotion,m.imageURL,p.usercode,p.usedNumberTimes,m.top,m.type1 AS type FROM t_animation m LEFT JOIN t_device_product p "
            . " ON p.usercode = '" . $usercode . "' AND p.flashcode = m.flashcode AND p.type = 1 AND m.top = 1 AND m.status = 1 ORDER BY m.num LIMIT " . $start . "," . $limit;
    $sql = "SELECT DISTINCT m.flashcode AS code,m.name,m.url,m.version,m.price,m.goodprice,m.promotion,m.imageURL,m.type1 AS type,(SELECT COUNT(flashcode) FROM t_device_product WHERE usercode = '" . $usercode . "' AND type = 1 AND flashcode = m.flashcode) AS isDownload FROM t_animation m WHERE  m.top = 1 AND m.status = 1 ORDER BY m.num LIMIT " . $start . "," . $limit;
    if (isset($_GET['month'])) {
        $sql = "SELECT DISTINCT m.flashcode AS code,m.name,m.url,m.version,m.price,m.goodprice,m.promotion,m.imageURL,m.type1 AS type,(SELECT COUNT(flashcode) FROM t_device_product WHERE usercode = '" . $usercode . "' AND type = 1 AND flashcode = m.flashcode) AS isDownload FROM t_animation m WHERE m.status = 1 AND m.month = '" . trim($_GET['month']) . "' ORDER BY m.flashcode";
    }
    $data = $db->fetchData($sql);
    if (checkArrayNotEmpty($data)) {
        $result['errorNo'] = "0";
        $result['errorMsg'] = "";
        for ($i = 0; $i < count($data); $i++) {
            if (!isNull($data[$i]['isDownload']) && $data[$i]['isDownload'] > 0) {
                $data[$i]['isDownload'] = "1";
            } else {
                $data[$i]['isDownload'] = "0";
            }
            if (isNull($data[$i]['promotion'])) {
                $data[$i]['promotion'] = "0";
            }
        }
        $resultArray['animation'] = $data;
    }
    echo json_encode($data);
} else {
    $result['errorNo'] = "1";
    $result['errorMsg'] = "提交参数不完整";
}
?>
